/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package actions;

import actionForms.CalculForm;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Hippolyte
 */
public class CalculAction extends org.apache.struts.action.Action {

    private static final String SUCCESS = "success";

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {

        CalculForm f;

        ServletContext context = this.getServlet().getServletContext();
        f = (CalculForm) context.getAttribute("CalculForm");

        if (f == null || f.personnes == null || f.personnes.isEmpty()) {

                System.out.println("new calcul form");
                f = new CalculForm();
                f.initDeserialisation();
        }

        context.setAttribute("CalculForm", f);


        return mapping.findForward(SUCCESS);
    }
}
